home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ttga10.zip / DOSUTIL.C < prev    next >
C/C++ Source or Header  |  1992-05-19  |  4KB  |  118 lines

  1. /*****************************************************************************
  2.  
  3.     Tools per utility DOS - Di Davide Achilli - 18 Maggio 1992
  4.  
  5. *****************************************************************************/
  6. #include <dir.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include "DosUtil.h"
  10.  
  11. #define MAX_FLAGS  20
  12. #define MAX_PATHS   5
  13. #define PATH_LEN   80
  14.  
  15. char paths [MAX_PATHS][PATH_LEN];
  16. int  flags [MAX_FLAGS];
  17. char validList [MAX_FLAGS];
  18.  
  19. /*----------------------------------------------------------------------------
  20.     Questa funzione analizza gli argc/argv e compila una lista speciale di
  21.     parametri
  22. ----------------------------------------------------------------------------*/
  23. TParRes analyzeParams (int argC, char *argV [], char *valid)
  24. {
  25.     int i;
  26.     int availPath = 0;
  27.     char *ptr;
  28.     strcpy (validList, valid);
  29.  
  30.     /*--------------------------------------------------------------------------
  31.         Resetta tutte le variabili flags.
  32.     --------------------------------------------------------------------------*/
  33.     for (i = 0; i < MAX_FLAGS; flags [i++] = 0);
  34.  
  35.     /*--------------------------------------------------------------------------
  36.         Resetta tutte le variabili paths.
  37.     --------------------------------------------------------------------------*/
  38.     for (i = 0; i < MAX_PATHS; paths [i++][0] = (char) 0);
  39.  
  40.     /*--------------------------------------------------------------------------
  41.         Scanna i parametri uno per uno...
  42.     --------------------------------------------------------------------------*/
  43.     for (i = 1; i < argC; i++) {
  44.  
  45.         /*------------------------------------------------------------------------
  46.             Controlla l'eventuale presenza del carattere '/' o '-' come primo
  47.             carattere di un parametro che denota la    presenza di un parametro.
  48.         ------------------------------------------------------------------------*/
  49.         if (strchr ("-/", argV [i][0]) != NULL) {
  50.  
  51.             /*----------------------------------------------------------------------
  52.                 Vede se il parametro flag esiste nella lista inviata e in che posi-
  53.                 zione e'.
  54.             ----------------------------------------------------------------------*/
  55.             if ((ptr = strchr (valid, toupper (argV [i][1]))) != NULL) {
  56.                 flags [(int) (ptr - valid)] = 1;
  57.             }
  58.             else return parUnknown;
  59.         }
  60.  
  61.         /*------------------------------------------------------------------------
  62.             Se no e' un path!
  63.         ------------------------------------------------------------------------*/
  64.         else {
  65.             strcpy (paths [availPath], argV [i]);
  66.             availPath ++;
  67.         }
  68.     }
  69.     if (i == 1) return parMissing;
  70.     return parOk;
  71. }
  72.  
  73. /*----------------------------------------------------------------------------
  74.     Ritorna, in base alla lettera richiesta, se era true o no.
  75. ----------------------------------------------------------------------------*/
  76. int flag (char letter)
  77. {
  78.     char *ptr;
  79.  
  80.     /*----------------------------------------------------------------------
  81.         Vede se il parametro flag esiste nella lista inviata e in che posi-
  82.         zione e'.
  83.     ----------------------------------------------------------------------*/
  84.     if ((ptr = strchr (validList, letter)) != NULL) {
  85.         return flags [(int) (ptr - validList)];
  86.     }
  87.     return 0;
  88. }
  89.  
  90. /*----------------------------------------------------------------------------
  91.     Ritorna il puntatore dell'n-esimo path inserito o NULL se il path richies-
  92.     to non e' stato inserito dall'utente.
  93. ----------------------------------------------------------------------------*/
  94. char *path (int n)
  95. {
  96.     if ((n < 0) || (n >= MAX_PATHS)) return NULL;
  97.     if (paths [n][0] == 0) return NULL;
  98.     return paths [n];
  99. }
  100.  
  101. /*----------------------------------------------------------------------------
  102.     Cambia l'estensione ad un path se questa manca.
  103. ----------------------------------------------------------------------------*/
  104. void changeExt (char *path, char *newExt)
  105. {
  106.     char drive [MAXDRIVE];
  107.     char dir   [MAXDIR];
  108.     char file  [MAXFILE];
  109.     char ext   [MAXEXT];
  110.     int flags;
  111.  
  112.     flags = fnsplit (path, drive, dir, file, ext);
  113.  
  114.     if (!(flags & EXTENSION)) {
  115.         fnmerge (path, drive, dir, file, newExt);
  116.     }
  117. }
  118.